package start.demo01.datatype.json.entity.editor;

import com.alibaba.fastjson.JSONObject;
import start.demo01.datatype.json.json.JSONPath;

import java.util.Iterator;
import java.util.LinkedList;

//过滤器
public class JSONConfigChain extends LinkedList<JSONPath> {

    public static JSONConfigChain builder() {
        return new JSONConfigChain();
    }

    public JSONConfigChain chain(JSONPath jsonPath) {
        add(jsonPath);
        return this;
    }

    public JSONConfigChain(JSONPath... editors) {
        for (JSONPath editor : editors) {
            add(editor);
        }
    }

    public void execute(JSONObject t) {
        Iterator<JSONPath> iterator = iterator();
        while (iterator.hasNext()) {
            JSONPath next = iterator.next();
            next.resolve(t);
        }
    }
}
